#ifndef PARSECANDATA_H
#define PARSECANDATA_H

/********协议解析******
***1、标的内部，如BMS205就是允许公司都能看见，其他的没标明的都是所有人能看见的，如BMS204，208等*/


#include <QObject>
#include <QTimer>
#include "ControlCAN.h"
#include "common.h"

#define ParseCANDataIns ParseCANData::Instance()

class ParseCANData : public QObject
{
    Q_OBJECT
public:
    explicit ParseCANData(QObject *parent = nullptr);

    static ParseCANData *Instance();

public:
    //以下是外部
    void parseBMS204(const QStringList &frame);
    void parseBMS208(const QStringList &frame);
    void parseBMS36A(const QStringList &frame);
    void parseBMS36B(const QStringList &frame);
    void parseBMS35A(const QStringList &frame);
    void parseBMS39B(const QStringList &frame);
    void parseVCU253(const QStringList &frame);

    //以下是内部
    void parseBMS205(const QStringList &frame);
    void parseBMS38A(const QStringList &frame);
    void parseBMS39A(const QStringList &frame);
    void parseBMS37B(const QStringList &frame);
    void parseBMS3E4(const QStringList &frame);

private:
    quint32 extractSignal(const QStringList &frame, int startByte, int startBit, int bitLength);

signals:
    void flushUIBMS204(double battVolt,double battCurr,double soc);
    void flushUIBMS208View(const QList<BMS_Normal> &modelData);
    void flushUIBMS208(int InsResVal);
    void flushUIBMS36A(double maxCellVolt,double minCellVolt,double maxCvNO,double MinCvNO);
    void flushUIBMS36B(double maxCellTemp,double maxCtNO,double minCellTemp,double minCtNO,double avrgCellTemp);
    void flushUIBMS35A(double chgPwr,double disChgPwr,double chgAmount,double disChgAmount);
    //void flushUIBMS39B(const QList<BMS_Normal> &modelData);
    void flushUIBMS39B(int Insulation_Fault, int BMS_Interlock_Fault);
    void flushUIVCU253(int hV_bat_power_enable,int vehicle_charge_state);
    void addAlarm(const AlarmData &data);

private:
    QList<BMS_Normal> m_modeldata_208;
    QList<BMS_Normal> m_modeldata_39B;

    AlarmData m_alarmData;

    CanDatas m_candatas;
    QTimer *m_timer;

    bool alarm_208_flag = false;
    bool alarm_39B_flag = false;
};

#endif // PARSECANDATA_H
